import { Component, OnInit } from '@angular/core';
import { HeroService } from '../../../services/hero.service';
import { StorageService } from '../../../services/storage.service';
import { NzMessageService,NzModalService } from 'ng-zorro-antd';

@Component({
  selector: 'app-myfeedback',
  templateUrl: './myfeedback.component.html',
  styleUrls: ['./myfeedback.component.css']
})
export class MyfeedbackComponent implements OnInit {

  loading = true;
  btn_loading=false;
  isVisible = false;
  public type:string='';
  public userType:string='';
  public details:string='';
  public status:string='';
  public userinfo:string;
  public maintinfo:string;
  public feedbacklist:Array<any>=[];
  public id:number;
  public remark:string='';
  public PageIndex:number=1;
  public PageSize:number=10;
  public PageTotal:number;
  constructor(private heroService: HeroService,
              private message:NzMessageService,
              private modalService: NzModalService,
              private storageService: StorageService) { }

  ngOnInit() {
    this.getFeedbacklist();
  }

  //获取设备抄表列表数据
  getFeedbacklist(){
    this.btn_loading=true;
    let url=host+"/main/merchantFeedback/list";
    let model="type="+this.type+"&userType="+this.userType+"&detailsLike="+this.details+"&status="+this.status+"&page="+this.PageIndex+"&pageSize="+this.PageSize;
    this.heroService.post(url,model).then(result=>{
      this.btn_loading=false;
      if(result.code==0){
        this.feedbacklist=result.data.pageBean.result;
        this.maintinfo=result.data.connectMaint;
        this.userinfo=result.data.connectUser;
        this.PageIndex=result.data.pageBean.curPage;  
        this.PageTotal=result.data.pageBean.totalRow;
        this.loading=false;
      }else{
        this.modalService.error({
          nzTitle: '提示',
          nzContent: result.msg
        });
      }
    })
  }

  read(id,status){
    if(status == 0){
      this.id=id;
      this.isVisible = true;
    }
  }
  handleOk(): void {
    this.btn_loading=true;
    let url=host+"/main/merchantFeedback/read";
    let model="id="+this.id+"&remark="+this.remark;
    this.heroService.post(url,model).then(result=>{
      this.btn_loading=false;
      this.isVisible = false;
      if(result.code==0){
        this.message.success('设置已读成功！');
        this.getFeedbacklist();
      }else{
        this.modalService.error({
          nzTitle: '提示',
          nzContent: result.msg
        });
      }
    })
  }

  handleCancel(): void {
    this.isVisible = false;
  }

  //分页
  PageIndexChange(event){
    this.PageIndex=event;
    this.getFeedbacklist();
  }
}
